Repository navigation
[lexical-playground] Bug Fix: Keep a chip's time when a day is picked - #9933
Conversation
## Description Follow-up to #9930. The date picker shows an instant at local midnight without a time, and picking a day for it stored an all-day date, so the time was lost. Two ways to get there: - A chip set to 09:00 in Seoul is 00:00 in London. Picking a day in a London tab made it all-day for everyone. - A user types 00:00, closes the picker, reopens it and picks a day. `handleDaySelect` now keeps an instant an instant: with no time to apply, it stores local midnight of the picked day, which is what it did before #9930. Only an all-day date or a chip without a date stays all-day. To make an older all-day chip (local midnight) a real all-day date, check and uncheck the time box. ## Changeset None, playground only. ## Test plan ### Before `(p)` and `(q)` are new in `DateTimeComponent.test.tsx`, run on `main` (America/New_York): ``` $ pnpm vitest run --project unit packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx × (p) keeps a timed chip at local midnight timed when a day is picked 67ms × (q) keeps a typed 00:00 when a day is picked after reopening 116ms AssertionError: expected '2026-11-01' to be '2026-11-01T04:00:00.000Z' // Object.is equality AssertionError: expected '2026-11-01' to be '2026-11-01T04:00:00.000Z' // Object.is equality Tests 2 failed | 17 passed (19) ``` ### After ``` $ pnpm vitest run --project unit packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx Tests 19 passed (19) $ pnpm vitest run --project unit packages/lexical-playground/__tests__/unit/DateTime Test Files 6 passed (6) Tests 98 passed (98) $ pnpm vitest run --project unit packages/lexical-playground Test Files 40 passed (40) Tests 491 passed (491) ``` The DateTime tests also pass (98/98) with `TZ` set to Europe/London, Asia/Seoul, Pacific/Apia, Pacific/Kiritimati, Pacific/Pago_Pago, Atlantic/Azores, America/Santiago and Asia/Kolkata. `tsc`, ESLint and Prettier are clean. I did not run the e2e suites locally; CI covers them.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
This looks good to me. Keeping a midnight instant as an instant when a day is picked fixes the lost time in both cases from the description. The new tests (p) and (q) fail on main with the all-day value and pass here. The suggestions below are optional and non-blocking.
Optional suggestions
- Let the time box describe a midnight instant. In
packages/lexical-playground/src/nodes/DateTimeNode/DateTimeComponent.tsx,includeTime(line 99) is false for an instant at local midnight, becausegetTimeValuehides midnight. The picker therefore opens with the time box unchecked and empty. After this change, a day pick keeps that chip timed (lines 201-202), so the box no longer predicts the result. For example, a London user picking a day for a chip set to 09:00 in Seoul sees "no time" before and after the pick, while the Seoul user still sees 09:00. You could open the picker with the box checked (00:00) for any non-empty instant and keep the chip text without a time. Unchecking would then be the visible way to make a chip all-day. - Test the check-then-uncheck route. The description says that checking and then unchecking the time box turns an older all-day chip into a real all-day date. That works: a chip at
localInstant(2026, 11, 4)becomes2026-11-04. But no test covers it for a midnight chip, since test (b) starts from 09:00. A test next to (p) inpackages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsxwould keep the route working.
No changeset is needed: AGENTS.md and CONTRIBUTING.md exempt playground-only changes.
| node.setAllDayDate(date); | ||
| } else { | ||
| node.setDateTime(withTime(date, time)); | ||
| node.setDateTime(withTime(date, [0, 0])); |
There was a problem hiding this comment.
Optional, non-blocking: this branch keeps a midnight instant timed, but for that chip includeTime (line 99) is false, so the picker shows the time box unchecked and empty both before and after the pick. A London user picking a day for a chip set to 09:00 in Seoul sees "no time" while Seoul keeps 09:00. You could open the picker with the box checked (00:00) whenever the value is a non-empty instant, so that unchecking is the visible way to go all-day.
…day from the time box
## Description
Adds test `(r)`: checking and then unchecking the time box turns a chip at local midnight, such as an older all-day chip, into an all-day date.
## Test plan
### After
```
$ pnpm vitest run --project unit packages/lexical-playground/__tests__/unit/DateTimeComponent.test.tsx
Tests 20 passed (20)
```
There was a problem hiding this comment.
This looks good to me. Keeping a midnight instant as an instant when a day is picked fixes the lost time in both cases from the description. The new tests (p) and (q) fail on main with the all-day value and pass here. Thanks for adding (r): it now covers the check-then-uncheck route the description gives for older all-day chips.
Optional, non-blocking
- Let the time box describe a midnight instant (
packages/lexical-playground/src/nodes/DateTimeNode/DateTimeComponent.tsx, lines 98-99).includeTimeis false for an instant at local midnight, becausegetTimeValuehides midnight, so the picker opens with the time box unchecked and empty. After this change, a day pick keeps that chip timed (lines 201-202), so the box no longer predicts the result. For example, a London user picking a day for a chip set to 09:00 in Seoul sees "no time" before and after the pick, while the Seoul user still sees 09:00. If the picker opened with the box checked (00:00) for any non-empty instant, unchecking it would be the visible way to make a chip all-day. The first assertion of (r) would change with it. This is the same point as the earlier inline comment on line 202, and a follow-up pull request is fine.
No changeset is needed: AGENTS.md and CONTRIBUTING.md exempt playground-only changes.
Description
Follow-up to #9930. The date picker shows an instant at local midnight without a time, and picking a day for it stored an all-day date, so the time was lost. Two ways to get there:
handleDaySelectnow keeps an instant an instant: with no time to apply, it stores local midnight of the picked day, which is what it did before #9930. Only an all-day date or a chip without a date stays all-day. To make an older all-day chip (local midnight) a real all-day date, check and uncheck the time box (test(r)).Changeset
None, playground only.
Test plan
Before
(p)and(q)are new inDateTimeComponent.test.tsx, run onmain(America/New_York):After
The DateTime tests also pass (99/99) with
TZset to Europe/London, Asia/Seoul, Pacific/Apia, Pacific/Kiritimati, Pacific/Pago_Pago, Atlantic/Azores, America/Santiago and Asia/Kolkata.tsc, ESLint and Prettier are clean. I did not run the e2e suites locally; CI covers them.